package com.baor.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baor.dao.TagFieldDao;
import com.baor.domain.ServiceVo;
import com.baor.domain.field.TagField;
import com.baor.service.TagFieldService;
import com.baor.utils.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;
@Service

public class TagFieldServiceImpl implements TagFieldService {
    @Autowired
    private TagFieldDao tagFieldDao;

    @Override
    public AjaxResult<?> tagFieldList(Map<String, Object> params) {
        params.put("pageIndex", (int)params.get("pageSize") * ((int)(params.get("pageIndex")) - 1));
        params.put("pageSize", params.get("pageSize"));
        Map<String,Object> res = new HashMap<>();
        res.put("tagFieldList",tagFieldDao.tagFieldList(params));
        res.put("pageCount",tagFieldDao.pageCount(params));
        return AjaxResult.success(res);
    }

    @Override
    public AjaxResult<?> tagFieldInfo(TagField tagField) {
        TagField tagFieldInfo = tagFieldDao.selectById(tagField.getTagId());
        return AjaxResult.success(tagFieldInfo);
    }


    @Override
    public AjaxResult<?> insertTagField(TagField tagField) {
        int row = tagFieldDao.insert(tagField);
        if (row > 0) {
            return AjaxResult.success();
        } else {
            return AjaxResult.error("添加失败");
        }
    }

    @Override
    public AjaxResult<?> updateTagField(TagField tagField) {
        int row = tagFieldDao.updateById(tagField);
        if (row > 0) {
            return AjaxResult.success();
        } else {
            return AjaxResult.error("修改失败");
        }
    }

    @Override
    public AjaxResult<?> deleteTagField(TagField tagField) {
        tagField.setDelflag(1);
        int row = tagFieldDao.updateById(tagField);
        if (row > 0) {
            return AjaxResult.success();
        } else {
            return AjaxResult.error("删除失败");
        }
    }

    @Override
    public AjaxResult<?> tagFieldSelect(Integer siteId) {
        QueryWrapper<TagField> wrapper = new QueryWrapper<>();
        wrapper.eq("delflag", 0).eq("site_id", siteId);
        return AjaxResult.success(tagFieldDao.selectList(wrapper));
    }
}
